package com.masterclient.app.widget;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;

/**
 * 作者：sean
 * 创建时间：2017/6/16 16:41
 * 功能说明：
 */

public class StaggeredGoodsItemDecoration extends RecyclerView.ItemDecoration{

    int offset;
    public StaggeredGoodsItemDecoration(int offset) {
        this.offset = offset*2/5;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
//        int position = parent.getChildAdapterPosition(view);
        StaggeredGridLayoutManager.LayoutParams params = (StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams();
        int spanIndex = params.getSpanIndex();
        if(spanIndex%2 == 0){
            outRect.set(offset*4,offset*9/4,offset*5/4,0);
        }else {
            outRect.set(offset,offset*9/4,offset*4,0);
        }

    }
}
